package migrations

import (
	"github.com/goravel/framework/contracts/database/schema"
	"github.com/goravel/framework/facades"
)

type M20250703094437CreateSysConfigTable struct {
}

// Signature The unique signature for the migration.
func (r *M20250703094437CreateSysConfigTable) Signature() string {
	return "20250703094437_create_sys_config_table"
}

// Up Run the migrations.
func (r *M20250703094437CreateSysConfigTable) Up() error {
	if !facades.Schema().HasTable("sys_config") {
		return facades.Schema().Create("sys_config", func(table schema.Blueprint) {
			table.ID()
			table.String("category", 50).Comment("参数分组")
			table.SmallInteger("type").Default(0).Comment("参数类型")
			table.String("name").Comment("名称")
			table.String("cache_key").Comment("键值")
			table.String("value").Comment("值")
			table.TinyInteger("visible").Comment("是否可见")
			table.String("remark", 500).Comment("备注")
			table.Integer("creator_id").Default(0).Comment("创建人ID")
			table.String("creator_name").Default("").Comment("创建人名称")
			table.TimestampsTz()

			table.Unique("cache_key")
			table.Index("name")
		})
	}

	return nil
}

// Down Reverse the migrations.
func (r *M20250703094437CreateSysConfigTable) Down() error {
	return facades.Schema().DropIfExists("sys_config")
}
